package hust.hiepdv.javaproject.model;

import java.awt.Image;
import java.awt.Toolkit;

public class Pad extends DrawableObject {

	public static final int STYLE_1 = 1;
	public static final int STYLE_2 = 2;
	public static final int STYLE_3 = 3;
	public static final int STYLE_4 = 4;
	private static final String STYLE_1_HORIZONTAL_DIR = "pic\\pad_h_style1.png";
	private static final String STYLE_2_HORIZONTAL_DIR = "pic\\pad_h_style2.png";
	private static final String STYLE_3_HORIZONTAL_DIR = "pic\\pad_h_style3.png";
	private static final String STYLE_4_HORIZONTAL_DIR = "pic\\pad_h_style4.png";
	private static final String STYLE_1_VERTICAL_DIR = "pic\\pad_v_style1.png";
	private static final String STYLE_2_VERTICAL_DIR = "pic\\pad_v_style2.png";
	private static final String STYLE_3_VERTICAL_DIR = "pic\\pad_v_style3.png";
	private static final String STYLE_4_VERTICAL_DIR = "pic\\pad_v_style4.png";
	public static final int HORIZONTAL = 1;
	public static final int VERTICAL = 2;
	public static final int velocity = 3;	

	private int maxX;
	private int minX;
	private int maxY;
	private int minY;
	private int orientation;
	boolean moveLeft = false;
	boolean moveRight = false;
	boolean moveDown = false;
	boolean moveUp = false;

	private int[] polyXs;
	private int[] polyYs;

	public Pad(int x, int y, Image image) {
		super(x, y, image);
	}

	/**
	 * Creat a pad with style (color) and orientation (2 options: horizontal and
	 * vertical)
	 * 
	 * @param x
	 * @param y
	 * @param style
	 * @param orientation
	 */
	public Pad(int x, int y, int style, int orientation) {
		super(x, y, null);
		Image image = null;
		if (orientation == HORIZONTAL) {
			this.orientation = HORIZONTAL;
			maxX = 550;
			minX = 50;
			setHeight(10);
			setWidth(100);
			switch (style) {			
			case STYLE_1:
				image = Toolkit.getDefaultToolkit().getImage(
						STYLE_1_HORIZONTAL_DIR);
				break;
			case STYLE_2:
				image = Toolkit.getDefaultToolkit().getImage(
						STYLE_2_HORIZONTAL_DIR);
				break;
			case STYLE_3:
				image = Toolkit.getDefaultToolkit().getImage(
						STYLE_3_HORIZONTAL_DIR);
				break;
			case STYLE_4:
				image = Toolkit.getDefaultToolkit().getImage(
						STYLE_4_HORIZONTAL_DIR);
				break;
			default:
				break;
			}
		}
		if (orientation == VERTICAL) {
			this.orientation = VERTICAL;
			setHeight(100);
			setWidth(10);
			switch (style) {
			case STYLE_1:
				image = Toolkit.getDefaultToolkit().getImage(
						STYLE_1_VERTICAL_DIR);
				break;
			case STYLE_2:
				image = Toolkit.getDefaultToolkit().getImage(
						STYLE_2_VERTICAL_DIR);
				break;
			case STYLE_3:
				image = Toolkit.getDefaultToolkit().getImage(
						STYLE_3_VERTICAL_DIR);
				break;
			case STYLE_4:
				image = Toolkit.getDefaultToolkit().getImage(
						STYLE_4_VERTICAL_DIR);
				break;
			default:
				break;
			}
		}
		setImage(image);
		polyXs = new int[] { x, x + width, x + width, x };
		polyYs = new int[] { y, y, y + height, y + height };
	}

	public void move(){
		switch (orientation) {
		case HORIZONTAL:
			if(moveLeft){
				if(this.x - this.velocity > minX){
					this.x -= this.velocity;
				}
			} else {
				if(moveRight){
					if(this.x + this.velocity < maxX - width){
						this.x += this.velocity;
					}
				}
			}
			break;
		case VERTICAL:
			if(moveUp){
				if(this.y - this.velocity > minY)
				{
					this.y -= this.velocity;
				}
			} else {
				if (moveDown){
					if(this.y + this.velocity < maxY - height){
						this.y += this.velocity;
					}
				}
			}
			break;
		default:
			break;
		}
	}

	
	public int getMaxX() {
		return maxX;
	}

	public void setMaxX(int maxX) {
		this.maxX = maxX;
	}

	public int getMaxY() {
		return maxY;
	}

	public void setMaxY(int maxY) {
		this.maxY = maxY;
	}

	public boolean isMoveLeft() {
		return moveLeft;
	}

	public void setMoveLeft(boolean moveLeft) {
		this.moveLeft = moveLeft;
	}

	public boolean isMoveRight() {
		return moveRight;
	}

	public void setMoveRight(boolean moveRight) {
		this.moveRight = moveRight;
	}

	public boolean isMoveDown() {
		return moveDown;
	}

	public void setMoveDown(boolean moveDown) {
		this.moveDown = moveDown;
	}

	public boolean isMoveUp() {
		return moveUp;
	}

	public void setMoveUp(boolean moveUp) {
		this.moveUp = moveUp;
	}

	public int getOrientation() {
		return orientation;
	}

	public void setOrientation(int orientation) {
		this.orientation = orientation;
	}

	public static int getVelocity() {
		return velocity;
	}

	public int[] getPolyXs() {
		return polyXs = new int[] { x, x + width, x + width, x };		
	}

	public void setPolyXs(int[] polyXs) {
		this.polyXs = polyXs;
	}

	public int[] getPolyYs() {
		return polyYs = new int[] { y, y, y + height, y + height };
	}

	public void setPolyYs(int[] polyYs) {
		this.polyYs = polyYs;
	}

}
